import os

env = Environment()

# 设置Python脚本安装路径
app_dir = '/boot/system/apps/Scel2Cin'
py_dir = os.path.join(app_dir, 'src')

# 需要安装的Python源文件
py_files = [
    'src/scel2cin_gui.py',
    'src/scel2txt.py',
    'src/txt2cin.py'
]

# 安装Python源文件
for py_file in py_files:
    env.Install(py_dir, py_file)

# 创建启动脚本
launch_script = '''#!/bin/sh
python3 /boot/system/apps/Scel2Cin/src/scel2cin_gui.py
'''

env.Command('Scel2Cin', None,
    [
        'echo "%s" > $TARGET' % launch_script,
        'chmod +x $TARGET'
    ]
)
env.Install(app_dir, 'Scel2Cin')

# 安装应用程序图标
env.Install('/boot/system/data/icons/scalable/apps', 'scel2cin.svg')

# 创建桌面快捷方式
desktop_entry = '''application/x-vnd.scel2cin
Scel2Cin
Sogou SCEL File Converter
/boot/system/apps/Scel2Cin/Scel2Cin
scel2cin
'''

env.Command('Scel2Cin.desktop', None,
    'echo "%s" > $TARGET' % desktop_entry
)
env.Install('/boot/home/config/settings/deskbar/menu/Applications', 'Scel2Cin.desktop')

# 设置默认目标
env.Default(app_dir)